package com.xlf.common.model;

import java.util.ArrayList;
import java.util.List;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;


@SuppressWarnings("serial")
public class OrderItem extends Model<OrderItem>{
	
	public static final OrderItem dao = new OrderItem();
	
	public Page<OrderItem> exeFidByOid(String o_id) {
		StringBuffer whee = new StringBuffer(" from orderitem where 1=1 ");
		List<Object> param = new ArrayList<Object>();

		if (o_id != null && !"".equals(o_id.trim())) {
			whee.append(" and o_id = ?");
			param.add( o_id );
		}

		whee.append(" order by o_id asc ");
		return paginate(1, 10, "select *", whee.toString(),
				param.toArray());
	}
	
	public Page<OrderItem> exeOrderItemConfirm(int pageNumber, int pageSize,
			String o_id,String createtime,String status, int f_id) {
		//SELECT * FROM orderitem a LEFT JOIN orderinfo b on a.o_id = b.o_id where a.f_id = 4;
		StringBuffer whee = new StringBuffer(" from orderitem a  LEFT JOIN orderinfo b on a.o_id = b.o_id ");
		List<Object> param = new ArrayList<Object>();

		if (f_id > 0) {
			whee.append(" where a.f_id = ? ");
			param.add(f_id);
		}
		
		if (o_id != null && !"".equals(o_id.trim())) {
			whee.append(" and a.o_id like ?");
			param.add("%" + o_id + "%");
		}
		if (createtime != null && !"".equals(createtime.trim())) {
			whee.append(" and b.createtime >= ?");
			param.add(createtime);
		}
		if (status != null && !"".equals(status.trim())) {
			if(!"-1".equals(status)){
				whee.append(" and b.status = ?");
				param.add(status);
				
			}
		}

		whee.append(" order by a.f_id asc ");
		return paginate(pageNumber, pageSize, "select *", whee.toString(),
				param.toArray());
	}
	
}
